﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using DiscoveryLogic.Analytics.BusinessLogic;
using DiscoveryLogic.Analytics.BusinessLogic.Rules;
using DiscoveryLogic.Analytics.DataObjects.Rules;
using DiscoveryLogic.Analytics.UI.Common.Events;
using Microsoft.Practices.Composite.Events;

namespace DiscoveryLogic.Analytics.Modules.DataNavigation
{
    public class RuleTreePresenter
    {
        private RuleTreeView _View;
		/// <summary></summary>
		public RuleTreeView View
		{
			get
			{
				return this._View;
			}
			set
			{
				this._View = value;
				if(this._View !=null)
				{
					this._View.RuleSelected += new RuleTreeView.OnRuleSelected(SelectRule);
				    this._View.PopulateTreeView(this.ReadRules());
				}
			}
		}

		private readonly IEventAggregator _EventAggregator;

        public RuleTreePresenter(IEventAggregator eventAggregator)
		{
			this._EventAggregator = eventAggregator;
		}

		public void SelectRule(RuleBase rule)
		{
            if (rule != null)
			{
				this._EventAggregator.GetEvent<RuleSelectedEvent>().Publish(rule);
			}
		}

        private ObservableCollection<RulesByType> ReadRules()
		{
            //ObservableCollection<RulesByType> allRules=new ObservableCollection<RulesByType>();
            //List<RuleBase> importRules = RuleManager.GetRulesByType(RuleType.Import, "../images/database.ico");
            //allRules.Add(new RulesByType(RuleType.Import, importRules));

            //List<RuleBase> linkRules = RuleManager.GetRulesByType(RuleType.Link, "../images/link.ico");
            //allRules.Add(new RulesByType(RuleType.Link, linkRules));

            //List<RuleBase> dedupRules = RuleManager.GetRulesByType(RuleType.Dedup, "../images/dedup.ico");
            //allRules.Add(new RulesByType(RuleType.Dedup, dedupRules));

            //return allRules;
            MyData.ReadAllRules();
            return MyData.AllRules;
		}
    }
}
